const { model } = require("../../models");
const { Op } = require("sequelize");
const uuid = require("uuid")
async function insertDownloadHistory({ ip = "", userId, oldFileName, downloadFileName, downloadFileId, createTime }) {
    var data = await model.downloadhistory.create({
        id: uuid.v4(),
        userId,
        ip, oldFileName, downloadFileName, downloadFileId, createTime
    })
    return JSON.parse(JSON.stringify(data))
}
async function selectDownloadHistoryUserId({ userId, startTime = "", endTime = "", pageSize = 10, pageNum = 1 }) {
    var findObj = {
        where: {
            userId,
        },
        limit: pageSize,
        offset: (pageNum - 1) * pageSize,
        order: [
            ['createTime', 'DESC'],
        ]
    }
    if (startTime && endTime) {
        findObj.where['createTime'] = {
            [Op.between]: [startTime, endTime]
        }
    }
    var data = await model.downloadhistory.findAndCountAll(findObj)
    return JSON.parse(JSON.stringify(data))
}
module.exports = {
    insertDownloadHistory,
    selectDownloadHistoryUserId
}